package main

import (
	"context"
	"github.com/SkyAPM/go2sky"
	"github.com/SkyAPM/go2sky/reporter"
	"github.com/robfig/cron"
	"log"
	"time"
)

type Hello struct {
	Str string
}

func (h Hello) Run() {
	log.Println(h.Str)
}

func main() {

	r, err := reporter.NewGRPCReporter("39.105.42.10:8011")
	if err != nil {
		log.Fatalf("new reporter error %v \n", err)
	}
	defer r.Close()
	tracer, err := go2sky.NewTracer("example", go2sky.WithReporter(r))
	span, ctx, err := tracer.CreateLocalSpan(context.Background())

	span.Log(time.Now(),"xxxxx")
	go2sky.TraceID(ctx)
	span.End()


	log.Println("Starting...")
	c := cron.New()
	h := Hello{"I Love You!"}
	// 添加定时任务
	c.AddJob("*/2 * * * * * ", h)
	// 添加定时任务
	c.AddFunc("*/5 * * * * * ", func() {
		log.Println("hello word")
	})

	s, err := cron.Parse("*/3 * * * * *")
	if err != nil {
		log.Println("Parse error")
	}
	h2 := Hello{"I Hate You!"}
	c.Schedule(s, h2)
	// 其中任务
	c.Start()
	// 关闭任务
	defer c.Stop()
	select {}
}
